// components/WikiPage.js
import { useState, useEffect } from 'react';
import axios from 'axios';

const HexoBlogPage = ({ pagePath }) => {
  const [content, setContent] = useState(null);
  const [loading, setLoading] = useState(true);
  const [error, setError] = useState(null);

  useEffect(() => {
    if (pagePath !="/undefined") {
      const fetchData = async () => {
        try {
          console.log(pagePath+"------------------")
          
          const response = await axios.get(`/api/hexo?path=${encodeURIComponent("blog"+pagePath)}`);
          setContent(response.data);
        } catch (err) {
          setError(err.message);
        } finally {
          setLoading(false);
        }
      };

      fetchData();
    }

  }, [pagePath]);

  if (loading) return <p>Loading...</p>;
  if (error) return <p>Error: {error}</p>;

  // 根据Wiki.js返回的数据结构，渲染内容
  return (
    <div dangerouslySetInnerHTML={{ __html: content }} />
  );
};

export default HexoBlogPage;